﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace APIDataManage.XmlToDB
{
    public class ModelsXml
    {
        public void insertModelToDB()
        {
            APIDataFunction api = new APIDataFunction();
            XmlDocument doc = api.getModels();
            if(doc != null)
            {
                XmlElement root = doc.DocumentElement;
                StringBuilder sb = new StringBuilder();

                foreach(XmlNode node in root.ChildNodes)
                {
                    sb.AppendFormat("insert into Boatmodels"+
                        "(id_model, model, nbdoucabin, nbsimcabin, heads, nbdbkcabin, nbdbedcabin, bt_frontpeak, createdate, updatedate) "+
                        "values({0},'{1}',{2},{3},{4},{5},{6},{7},'{8}','{9}');",
                        node.Attributes["id_model"].Value, 
                        node.Attributes["model"].Value,
                        node.Attributes["nbdoucabin"].Value,
                        node.Attributes["nbsimcabin"].Value,
                        node.Attributes["heads"].Value,
                        node.Attributes["nbdbkcabin"].Value,
                        node.Attributes["nbdbedcabin"].Value,
                        node.Attributes["bt_frontpeak"].Value,
                        DateTime.Now.ToString(),
                        DateTime.Now.ToString());
                }

                if(sb.Length > 0)
                {
                    SqlDbHelper.ExecteNonQuery(sb.ToString());
                }
            }

        }
    }
}
